package main

import (
	"flag"

	"google.golang.org/protobuf/compiler/protogen"
	"google.golang.org/protobuf/types/pluginpb"

	// 导入引来包
	_ "google.golang.org/genproto/googleapis/api/annotations"

	"gitee.com/jnshao/go-start/proto/tools/generator"
)

/*
	protoc插件开发参考：https://github.com/go-kratos/kratos/tree/main/cmd/protoc-gen-go-errors


	proto文件转FileDescriptorProto（替换protoc输入流方便调试）： https://github.com/jhump/protoreflect


    工作目录：C:/Users/JN-SH/Desktop/gitee.com/jnshao/go-start/proto/tools

*/

func main() {
	flag.Parse()
	var flags flag.FlagSet
	protogen.Options{
		ParamFunc: flags.Set,
	}.Run(func(gen *protogen.Plugin) error {
		gen.SupportedFeatures = uint64(pluginpb.CodeGeneratorResponse_FEATURE_PROTO3_OPTIONAL)
		// 遍历proto文件gen.Files
		for _, f := range gen.Files {
			if !f.Generate {
				continue
			}
			generator.GenerateFile(gen, f)
		}
		return nil
	})
}
